<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>自定义遍历数据</title>
</head>
<body>
    <script>
        const team = {
            name: '终极一班',
            members: [
                'xiaoming',
                'xiaoning',
                'xiaotian',
                'knight'
            ],
            //添加 Symbol.iterator 方法
            [Symbol.iterator]: function(){
                //元素的下标
                let index = 0;
                //返回指针对象
                return {
                    next: () => {
                        //返回对象 done: true
                        // let one = {value: this.members[0], done: false};
                        // let two = {value: this.members[1], done: false};
                        // let three = {value: this.members[2], done: false};
                        // let four = {value: this.members[3], done: false};
                        // let five = {value: undefined, done: true};
                        //最终返回的结果
                        let result = {value: this.members[index]};
                        //判断 done 的值
                        if(index >= this.members.length){
                            result.done = true;
                        }else{
                            result.done = false;
                        }
                        //自增
                        index++;
                        //返回结果
                        return result;
                    }
                }
            }
        }

        
        //for...of 遍历 
        // xiaoming  xiaoning  xiaotian  knight
        for(let v of team){
            console.log(v);
        }



    </script>
</body>

</html>